package sg.edu.nus.iss.jass.persistence;

import java.util.List;

import sg.edu.nus.iss.jass.datastore.BaseDAO;
import sg.edu.nus.iss.jass.datastore.exception.DataStoreException;
import sg.edu.nus.iss.jass.datastore.impl.Selector;
import sg.edu.nus.iss.jass.dto.JobSeeker;
import sg.edu.nus.iss.jass.dto.Resume;
import sg.edu.nus.iss.jass.util.Util;

/**
 * 
 * @author WANG DAYONG
 *
 */
public class ResumeDAO extends BaseDAO {
	
	/**
	 * find resumes by job seeker
	 * @param jobSeeker
	 * @return Collection of Resume belong to given jobseeker
	 * @throws DataStoreException Encounter error when load data
	 */
	public List<Resume> findResumes(JobSeeker jobSeeker) throws DataStoreException {
		List<String> resumeIds = jobSeeker.getIdList(jobSeeker.getResumeIds());
		if(!Util.isEmpty(resumeIds)) {
			return selectByIds(Resume.class, resumeIds.toArray(new String[0]));
		} else {
			return select(Resume.class, (new Selector()).eq("jobSeekerId", jobSeeker.getId()));
		}
		
	}
	
	/**
	 * Save Resume
	 * @param resume
	 * @throws DataStoreException
	 */
	public void saveResume(Resume resume) throws DataStoreException{
		save(resume);
	}
	
	/**
	 * 
	 * @param id
	 * @return
	 * @throws DataStoreException
	 */
	public Resume getResumeById(String id) throws DataStoreException{
		return selectById(Resume.class, id);
	}
}
